package com.hunktimes.wholesale.vm

import androidx.lifecycle.MutableLiveData
import com.hunktimes.wholesale.base.BaseViewModel
import com.hunktimes.wholesale.extension.launch
import com.hunktimes.wholesale.net.WholeSaleRepository
import com.hunktimes.wholesale.net.model.RecAddress

/**
 * Author: Delete
 * Date: 2020/8/14 10:45
 * Description:
 *
 */
class AddressVM : BaseViewModel() {
    val recAddrsResult = MutableLiveData<List<String>>()
    val defRecAddrResult = MutableLiveData<String>()

    val updateAddressResult = MutableLiveData<String>()

    fun getDefRecAddr(orderId: String) {
        launch({
            val resp = WholeSaleRepository.getDefRecAddr()
            val orders = resp.data
            orders?.let {
                defRecAddrResult.value = it
            }
        })
    }

    fun getRecAddrList() {
        launch({
            val resp = WholeSaleRepository.getRecAddrList()
            val orders = resp.data
            orders?.let {
                recAddrsResult.value = it
            }
        })
    }

    fun updateAddress() {
        launch({
            val recAddress = RecAddress(
                "Jax", "17071590613",
                "xihu", "sunking"
            )
            val resp = WholeSaleRepository.updateAddress(recAddress)
            val update = resp.data
            update?.let {
            updateAddressResult.value = it
            }
        })
    }
}